package com.cgnpc.scp.hr.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.common.bean.CreateFileInfo;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.hr.mybatis.entity.HrProcessRecord;
import com.cgnpc.scp.hr.service.HrProcessRecordService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**********************************
 * 用途说明: 调试人资管理 - 审批记录管理
 * 作者姓名: zhangyibing
 * 创建时间: 2020年11月11日10:09:14
 ***********************************/
@RestController
@RequestMapping("/scp/hr/processRecord")
public class HrProcessRecordController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HrProcessRecordController.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private HrProcessRecordService hrProcessRecordService;

    /**********************************
     * 用途说明: 调试人资管理 - 审批记录 - 列表
     * 参数说明 params
     * 返回值说明: 列表
     ***********************************/
    @ApiOperation(value="调试人资管理 - 审批记录 - 列表")
//    @UBA(module = "调试人资管理", action = "审批记录 - 列表", channel = OperatorType.Page)
    @RequestMapping(value = "/listPage", method = {RequestMethod.POST})
    public AjaxResult listPage(HttpServletRequest request, @RequestBody Map<String, Object> params) {
        try {
            MyPageResult<HrProcessRecord> result = hrProcessRecordService.queryListPage(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        } catch (Exception e) {
            LOGGER.error("HrProcessRecordController listPage error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 调试人资管理 - 审批记录 - 导出Excel
     * 参数说明: HttpServletRequest request, @RequestBody T reqEntity
     * 返回值说明: Object
     ***********************************/
    @ApiOperation(value = "调试人资管理 - 审批记录 - 导出Excel")
//    @UBA(module = "调试人资管理", action = "调试人资管理 - 审批记录 - 导出Excel", channel = OperatorType.Button)
    @RequestMapping(value = "/exportExcel", method = {RequestMethod.POST})
    @ResponseBody
    public Object exportExcel(HttpServletRequest request, @RequestBody Map<String, Object> params) {
        AjaxResult ajaxResult = null;
        try {
            CreateFileInfo createFileInfo = hrProcessRecordService.exportExcel(params);
            ajaxResult = AjaxResultUtil.createSuccessMessage(createFileInfo);
        } catch (Exception e) {
            LOGGER.error("exportExcel.error;", e);
            ajaxResult = AjaxResultUtil.createErrorMessage();
        }
        return ajaxResult;
    }
}
